import adraw.*;
import geometry.*;
import tester.*;
import java.util.*;
import colors.*;

/**
 * A ConsLoS is an ILoS which has a first and a rest
 * @author Ryan & Adam
 */
class ConsLoS implements ILoS{
  Star first; // Represents the first Star in the list.
  ILoS rest; 
  
  /**
   * Constructor
   * @param first Represents the first Star in the list.
   * @param rest Represents the rest of the list.
   */
  ConsLoS(Star first, ILoS rest) {
    this.first = first;
    this.rest = rest;
  }
  
  /*
   * TEMPLATE:
   * FIELDS:
   * ... this.first ...            --Star
   * ... this.rest ...             --ILoS
   *
   * METHODS:
   * ... this.drawStars(Canvas c) ...  -- boolean
   * ... this.onTick(Mfmwg m) ...      -- ILoS
   * ... this.foundStar(Mfmwg m) ...   -- boolean
   * ... this.caughtStar(Mfmwg m) ...  -- boolean
   *
   *
   * METHODS FOR FIELDS:
   * ... this.first.onTick() ...             -- Star
   * ... this.first.makeStar() ...           -- Star
   * ... this.first.hitGroundp() ...         -- boolean
   * ... this.first.isFoundp(Mfmwg m) ...    -- boolean
   * ... this.first.drawStar(Canvas c) ...   -- boolean
   * ... this.rest.drawStars(Canvas c) ...  -- boolean
   * ... this.rest.onTick(Mfmwg m) ...      -- ILoS
   * ... this.rest.foundStar(Mfmwg m) ...   -- boolean
   * ... this.rest.caughtStar(Mfmwg m) ...  -- boolean
   */ 
  
  /* (non-Javadoc)
   * @see ILoS#drawStars(adraw.Canvas)
   */
  public void drawStars(Canvas c){
    this.first.drawStar(c);
    this.rest.drawStars(c);
  }
  
  /* (non-Javadoc)
   * @see ILoS#onTick(Mfmwg)
   */
  public void onTick(Mfmwg m){
    if (this.first.span <= 0 || this.first.isFoundp(m) || this.first.hitGroundp()){
      first = this.first.makeStar();
      this.rest.onTick(m);
    } else { 
      this.first.onTick();
      this.rest.onTick(m);
    }
  }
  
  /* (non-Javadoc)
   * @see ILoS#foundStar(Mfmwg)
   */
  public boolean foundStar(Mfmwg m){
    return this.first.isFoundp(m) || this.rest.foundStar(m);
  }
  
  /* (non-Javadoc)
   * @see ILoS#caughtStar(Mfmwg)
   */
  public Star caughtStar(Mfmwg m){
    if(this.first.isFoundp(m)) {
      return this.first;
    } else { 
      return this.rest.caughtStar(m);
    }
  }
}